{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单号：</label>
                        <div class="layui-input-inline">
                            <input name="order_sn" class="layui-input" id="title" value="" type="text"
                                   placeholder="请输入订单号">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id" lay-verify="required" lay-search="">
                                <option value="0" ></option>
                                {volist name="merchant_list" id="t"}
                                <option value="{$t.id}" >{$t.name} - {$t.code}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">支付状态：</label>
                        <div class="layui-input-inline">
                            <select name="pay_status" >
                                <option value="" >请选择</option>
                                <option value="0" >未支付</option>
                                <option value="1" >已支付</option>
                                <option value="-1" >已退款</option>
                            </select>
                        </div>
                    </div>
					<div class="layui-inline">
					    <label class="layui-form-label">开票状态：</label>
					    <div class="layui-input-inline">
					        <select >
					            <option value="" >请选择</option>
					            <option value="0" >未开票</option>
					            <option value="1" >已开票</option>
					        </select>
					    </div>
					</div>

                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search"
                                lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i
                                class="layui-icon layui-icon-refresh"></i>{:__('Reset')}
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->


<!--<script type="text/html" id="toolbarDemo">-->
<!--    <div class="layui-btn-container">-->
<!--        <button type="button" lay-event="add" class="layui-btn {:node('Admin/addAdmin')} layui-btn-sm">添加安保人员</button>-->
<!--        <button type="button" lay-event="del" class="layui-btn {:node('Admin/del')} layui-btn-sm layui-btn-danger">-->
<!--            删除安保人员-->
<!--        </button>-->
<!--        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>-->
<!--    </div>-->
<!--</script>-->

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
<!--        <button type="button" lay-event="add"  class="layui-btn {:node('Admin/addAdmin')} layui-btn-sm">新增缴费单</button>-->
        <button type="button" lay-event="adminAdd"  class="layui-btn {:node('Life/addAdmin')} layui-btn-sm">人工缴费</button>
        <button type="button" lay-event="reload"  class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
    </div>
</script>

<script type="text/html" id="operationTpl">
 <!--   {{# if(d.pay_status==3){ }}
    <a href="javascript:;" class="layui-btn  layui-btn-xs {:node('Admin/addAdmin')}" data-title="审核" lay-event="edit"><i class="layui-icon">&#xe679;</i></a>
    {{# }else{ }}
     <a  class="layui-btn layui-btn-xs layui-btn-disabled" data-title="审核" ><i class="layui-icon">&#xe679;</i></a>
    {{# } }} -->
    {{# if(d.pay_status==1 || d.pay_status == -1){ }}
    <a href="javascript:;" class="layui-btn   layui-btn-xs {:node('Life/costPrint')}" data-title="打印" lay-event="print"><i class="layui-icon">&#xe66d;</i></a>
    {{# }else{ }}
	 <a  class="layui-btn layui-btn-disabled layui-btn-xs" data-title="打印" ><i class="layui-icon">&#xe66d;</i></a>
	{{# } }}
    <a href="javascript:;" class="layui-btn  layui-btn-primary layui-btn-xs {:node('Life/detail')}" data-title="查看详情" lay-event="detail"><i class="layui-icon">&#xe705;</i></a>
    <a href="javascript:;" class="layui-btn  layui-btn-danger layui-btn-xs {:node('Life/del')}" data-title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>


<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'opTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        form.render();

        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
              // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {title: 'ID', field: 'id',width:60},
                {title: '订单号', field: 'order_sn',align: 'center',width:200},
				{
				    title: '商户', field: 'merchant',align: 'center', width:200,templet: function (item) {
				        return item.merchant.merchant_sn + '|' + item.merchant.name + '|' +item.merchant.company
				    }
				},
                {title: '费用名称', field: 'fname',width:100},
				// {
				//     title: '费用名称', field: 'fname', templet: function (item) {
				//         if (item.cost_type_id == 1){
				//             return  '电费';
				//         } else if (item.cost_type_id == 2){
				//             return  '水费';
				//         } else {
				//             return  '位置缴费项';
				//         }
				//     }
				// },
				{title: '缴费单价', field: 'unit_price',templet: function (item) {
				    var unit_price = item.unit_price
				        return parseFloat(unit_price).toFixed(2) +'元'
				    }
				},
				{title: '购买量', field: 'number'},
				{title: '手续费', field: 'service_charge', templet: function (item) {
				        return item.service_charge/100 +'元'
				    }},
                {title: '缴费金额', field: 'real_amount', templet: function (item) {
                        return item.real_amount/100 +'元'
                    }},
                
                 {
                    title: '支付状态', field: 'pay_status', templet: function (item) {
                        if (item.pay_status == 0){
                            return  '未支付';
                        } else if (item.pay_status == 1){
                            return  '已支付';
                        } else if (item.pay_status == -1){
                            return  '已退款';
                        }  else {
                            return  '未知状态';
                        }
                    }
                 },
                {
                    title: '开票状态', field: 'invoice', templet: function (item) {
                        if (item.invoice == 0){
                            return  '<a href="javascript:;" class="layui-btn  layui-btn-sm  layui-btn-danger " lay-event="invoice">未开票</a>';
                        } else if (item.invoice == 1){
                            return  '<a href="javascript:;" class="layui-btn layui-btn-sm  layui-btn-primary "  lay-event="invoice">已开票</a>';
                        }
                    }
                },
				 // { title: '开票状态',align:'center',edit: 'text', field: ''},
				 // templet:function (item) {
				 //         var status = item.
				 //         if ( status== 0){
				 //             return '未开票'
				 //         } else{
				 //             return '已开票'
				 //         }
				 //     }},
              
                { title: '交费时间', field: 'pay_time',align: 'center',width:200},
                {templet: '#operationTpl', width: 200,align: 'center', title: '操作'}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "edit") {
                lucky.CreateOpenForm("审核提交","{:url('common/costEdit')}?id=" + _id);
                return false;
            } else if (layEvent === "del") {
                lucky.FormatData(_id, "{:url('del')}");
            }else if(layEvent==="print"){
                lucky.CreateOpenForm("打印","{:url('common/costPrint')}?id=" + _id,'85%');
                return false;
            }else if(layEvent==="detail"){
                lucky.CreateOpenForm("缴费详情","{:url('detail')}?id=" + _id);
                return false;
            }else if(layEvent==="invoice"){
                var datas = {} ;
                datas.id      = _id ;   //  购买数量
                $.ajax({
                    url:"{:url('invoice')}",
                    type:"post",
                    data: datas,
                    dataType:"json",
                    success:function(data){
                        layer.msg(data.msg,{icon:15,time:1000,shade:0.3});
                        window.location.reload();
                    }
                });
                return false;
            }
        });


        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            console.log(obj.event)
            if (obj.event === "add") {
                lucky.CreateOpenForm("添加 ", "{:url('add')}");
                return false;
            }else if(obj.event ==="edit"){
                lucky.CreateOpenForm("审核提交","{:url('common/costEdit')}?id=" + _id);
                return false;
            } else if (obj.event === "close") {
                opTables.closeAll();
            } else if (obj.event === "open") {
                opTables.openAll();
            } else if (obj.event === "reload") {
                lucky.CreateReload();
            } else if(obj.event==="adminAdd"){
                lucky.CreateOpenForm("添加人工缴费用","{:url('adminAdd')}");
                return false;
            }
        });



        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}
